package com.shop2cn.iapi.wxcomponent.testcase;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.shop2cn.iapi.wxcomponent.parameter.ConfirmAllAuditMchAppBean;
import com.shop2cn.iapi.wxcomponent.service.ConfirmAllAuditMchAppCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.PayGateWayCallService;
import com.ymttest.business.service.WxComponentService;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.Mchapp;
import com.ymttest.database.sqlwapper.godmch.DefGodMchWapper;
import com.ymttest.database.sqlwapper.godmch.mch_configWapper;
import com.ymttest.utils.TestDataManager;
/**
*小程序全网发布Test
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_ConfirmAllAuditMchApp{
	private static ConfirmAllAuditMchAppBean confirmallauditmchappBean;
	private static ConfirmAllAuditMchAppCall confirmallauditmchappCall;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("小程序全网发布Test");
	}

	@Before
	public void caseUp() {
		confirmallauditmchappBean=new ConfirmAllAuditMchAppBean();
		confirmallauditmchappCall=new ConfirmAllAuditMchAppCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(confirmallauditmchappCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConfirmAllAuditMchApp_001() {
		Logger.start(true,"发布一个小程序，成功");
		try {
			Mchapp mchapp = new DefGodMchWapper().selectMchappBycount(10).get(0);
			mchapp.setAppStatus(5);
			int updateMchAppByPrimaryKey = new DefGodMchWapper().updateMchAppByPrimaryKey(mchapp);
			
			
			//增加mock，消除存量数据
			LinkedHashMap<String,Object> m=new LinkedHashMap<>();
			m.put("mock", "mock-enable");
			m.put("mockId-1", TestDataManager.getRandomUUID().toString());
			m.put("mockApi-1", "wxcomponent-getTemplateList-Normal");
			m.put("mockId-2", TestDataManager.getRandomUUID().toString());
			m.put("mockApi-2", "wxcomponent-getCategory-Normal");
			m.put("mockId-3", TestDataManager.getRandomUUID().toString());
			m.put("mockApi-3", "wxcomponent-uploadCode-Normal");
			m.put("mockId-4", TestDataManager.getRandomUUID().toString());
			m.put("mockApi-4", "wxcomponent-submitAudit-Normal");
			m.put("mockParam-4-auditid", TestDataManager.getRandomNum(7));
			m.put("mockId-5", TestDataManager.getRandomUUID().toString());
			m.put("mockApi-5", "wxcomponent-release-Normal");
			PayGateWayCallService.addMock(confirmallauditmchappCall, m);
			confirmallauditmchappBean.setMchIds(Arrays.asList(mchapp.getMchId()));
			confirmallauditmchappCall.setData(confirmallauditmchappBean);
			confirmallauditmchappCall.callService();
			confirmallauditmchappCall.callService();			
			Logger.verifyEquals("200", confirmallauditmchappCall.getString("code"), "验证code");
			
			Mchapp mchapp1 = new DefGodMchWapper().selectMchappByExample(mchapp.getMchId()).get(0);
			Logger.verifyEquals(2, mchapp1.getAppStatus(),"验证此小程序已经重新发布");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConfirmAllAuditMchApp_002() {
		Logger.start(true,"重新发布多个小程序，成功");
		try {
			List<Mchapp> selectMchappBycount = new DefGodMchWapper().selectMchappBycount(10);
			List<Integer> mchIds = new ArrayList<>();
			for (Mchapp mchapp2 : selectMchappBycount) {
				mchapp2.setAppStatus(5);
				int updateMchAppByPrimaryKey = new DefGodMchWapper().updateMchAppByPrimaryKey(mchapp2);
				mchIds.add(mchapp2.getMchId());
			}
			//增加mock，消除存量数据
			LinkedHashMap<String,Object> m=new LinkedHashMap<>();
			m.put("mock", "mock-enable");
			m.put("mockId-1", TestDataManager.getRandomUUID().toString());
			m.put("mockApi-1", "wxcomponent-getTemplateList-Normal");
			m.put("mockId-2", TestDataManager.getRandomUUID().toString());
			m.put("mockApi-2", "wxcomponent-getCategory-Normal");
			m.put("mockId-3", TestDataManager.getRandomUUID().toString());
			m.put("mockApi-3", "wxcomponent-uploadCode-Normal");
			m.put("mockId-4", TestDataManager.getRandomUUID().toString());
			m.put("mockApi-4", "wxcomponent-submitAudit-Normal");
			m.put("mockParam-4-auditid",TestDataManager.getRandomUUID().toString());
			m.put("mockId-5", TestDataManager.getRandomUUID().toString());
			m.put("mockApi-5", "wxcomponent-release-Normal");
			PayGateWayCallService.addMock(confirmallauditmchappCall, m);
			confirmallauditmchappBean.setMchIds(mchIds);
			confirmallauditmchappCall.setData(confirmallauditmchappBean);
			confirmallauditmchappCall.callService();
			
			Logger.verifyEquals("200", confirmallauditmchappCall.getString("code"), "验证code");
			
			for (Mchapp mchapp2 : selectMchappBycount) {
				Mchapp mchapp1 = new DefGodMchWapper().selectMchappByExample(mchapp2.getMchId()).get(0);
				Logger.verifyEquals(2, mchapp1.getAppStatus(),"验证此小程序已经重新发布");
			}
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConfirmAllAuditMchApp_003() {
		Logger.start(true,"未填写mock，失败");
		try {
			Mchapp mchapp = new DefGodMchWapper().selectMchappBycount(10).get(0);
			mchapp.setAppStatus(5);
			int updateMchAppByPrimaryKey = new DefGodMchWapper().updateMchAppByPrimaryKey(mchapp);
			//不增加mock
			confirmallauditmchappBean.setMchIds(Arrays.asList(mchapp.getMchId()));
			confirmallauditmchappCall.setData(confirmallauditmchappBean);
			confirmallauditmchappCall.callService();
			confirmallauditmchappCall.callService();			
			Logger.verifyEquals("400", confirmallauditmchappCall.getString("code"), "验证code");
			Logger.verifyIsContains("获取最新模板列表失败", confirmallauditmchappCall.getString("message"), "验证code");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConfirmAllAuditMchApp_004() {
		Logger.start(true,"小程序状态为：1:已授权 待提审 3:审核失败 4:审核成功待发布5:已发布、  已经发布过的，进行重新发布");
		try {
			List<Mchapp> selectMchappBycount = new DefGodMchWapper().selectMchappBycount(10);
			selectMchappBycount.get(0).setAppStatus(1);
			selectMchappBycount.get(0).setIsPublished(true);
			selectMchappBycount.get(1).setAppStatus(3);
			selectMchappBycount.get(1).setIsPublished(true);
			selectMchappBycount.get(2).setAppStatus(4);
			selectMchappBycount.get(2).setIsPublished(true);
			selectMchappBycount.get(3).setAppStatus(5);
			selectMchappBycount.get(3).setIsPublished(true);
			new DefGodMchWapper().updateMchAppByPrimaryKey(selectMchappBycount.get(0));
			new DefGodMchWapper().updateMchAppByPrimaryKey(selectMchappBycount.get(1));
			new DefGodMchWapper().updateMchAppByPrimaryKey(selectMchappBycount.get(2));
			new DefGodMchWapper().updateMchAppByPrimaryKey(selectMchappBycount.get(3));
			
			
			//增加mock，消除存量数据
			LinkedHashMap<String,Object> m=new LinkedHashMap<>();
			m.put("mock", "mock-enable");
			m.put("mockId-1", TestDataManager.getRandomUUID().toString());
			m.put("mockApi-1", "wxcomponent-getTemplateList-Normal");
			m.put("mockId-2", TestDataManager.getRandomUUID().toString());
			m.put("mockApi-2", "wxcomponent-getCategory-Normal");
			m.put("mockId-3", TestDataManager.getRandomUUID().toString());
			m.put("mockApi-3", "wxcomponent-uploadCode-Normal");
			m.put("mockId-4", TestDataManager.getRandomUUID().toString());
			m.put("mockApi-4", "wxcomponent-submitAudit-Normal");
			m.put("mockParam-4-auditid", TestDataManager.getRandomNum(7));
			m.put("mockId-5", TestDataManager.getRandomUUID().toString());
			m.put("mockApi-5", "wxcomponent-release-Normal");
			PayGateWayCallService.addMock(confirmallauditmchappCall, m);
			
			confirmallauditmchappBean.setMchIds(Arrays.asList(selectMchappBycount.get(0).getMchId(),selectMchappBycount.get(1).getMchId(),selectMchappBycount.get(2).getMchId(),selectMchappBycount.get(3).getMchId()));
			confirmallauditmchappCall.setData(confirmallauditmchappBean);
			confirmallauditmchappCall.callService();
			Logger.verifyEquals("200", confirmallauditmchappCall.getString("code"), "验证code");
			
			for (int i = 0; i < 4; i++) {
				Mchapp mchapp1 = new DefGodMchWapper().selectMchappByExample(selectMchappBycount.get(i).getMchId()).get(0);
				Logger.verifyEquals(2, mchapp1.getAppStatus(),"验证此小程序已经重新发布");
				System.out.println(mchapp1);
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_ConfirmAllAuditMchApp_005() {
		Logger.start(true,"小程序状态为：1:已授权 待提审 3:审核失败 4:审核成功待发布5:已发布、  没有发布过的，进行重新发布");
		try {
			
			List<Mchapp> selectMchappBycount = new DefGodMchWapper().selectMchappBycount(10);
			selectMchappBycount.get(0).setAppStatus(1);
			selectMchappBycount.get(0).setIsPublished(false);
			selectMchappBycount.get(1).setAppStatus(3);
			selectMchappBycount.get(1).setIsPublished(false);
			selectMchappBycount.get(2).setAppStatus(4);
			selectMchappBycount.get(2).setIsPublished(false);
			selectMchappBycount.get(3).setAppStatus(5);
			selectMchappBycount.get(3).setIsPublished(false);
			new DefGodMchWapper().updateMchAppByPrimaryKey(selectMchappBycount.get(0));
			new DefGodMchWapper().updateMchAppByPrimaryKey(selectMchappBycount.get(1));
			new DefGodMchWapper().updateMchAppByPrimaryKey(selectMchappBycount.get(2));
			new DefGodMchWapper().updateMchAppByPrimaryKey(selectMchappBycount.get(3));
			//增加mock，消除存量数据
			LinkedHashMap<String,Object> m=new LinkedHashMap<>();
			m.put("mock", "mock-enable");
			m.put("mockId-1", TestDataManager.getRandomUUID().toString());
			m.put("mockApi-1", "wxcomponent-getTemplateList-Normal");
			m.put("mockId-2", TestDataManager.getRandomUUID().toString());
			m.put("mockApi-2", "wxcomponent-getCategory-Normal");
			m.put("mockId-3", TestDataManager.getRandomUUID().toString());
			m.put("mockApi-3", "wxcomponent-uploadCode-Normal");
			m.put("mockId-4", TestDataManager.getRandomUUID().toString());
			m.put("mockApi-4", "wxcomponent-submitAudit-Normal");
			m.put("mockParam-4-auditid", TestDataManager.getRandomNum(7));
			m.put("mockId-5", TestDataManager.getRandomUUID().toString());
			m.put("mockApi-5", "wxcomponent-release-Normal");
			PayGateWayCallService.addMock(confirmallauditmchappCall, m);
			confirmallauditmchappBean.setMchIds(Arrays.asList(selectMchappBycount.get(0).getMchId(),selectMchappBycount.get(1).getMchId(),selectMchappBycount.get(2).getMchId(),selectMchappBycount.get(3).getMchId()));
			confirmallauditmchappCall.setData(confirmallauditmchappBean);
			confirmallauditmchappCall.callService();
			confirmallauditmchappCall.callService();			
			Logger.verifyEquals("200", confirmallauditmchappCall.getString("code"), "验证code");
			for (int i = 0; i < 4; i++) {
				Mchapp mchapp1 = new DefGodMchWapper().selectMchappByExample(selectMchappBycount.get(i).getMchId()).get(0);
				Logger.verifyNotEquals(2, mchapp1.getAppStatus(),"验证此小程序已经重新发布");
			}
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
}